package com.rem.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Objects;

/**
 * @author remembrance
 * @version 1.0
 * @date 2021/11/15 9:02
 */
@Controller
public class LoginController {

    @GetMapping({"/","/login.html"})
    public String login(){
        return "login";
    }

    @GetMapping("/main.html")
    public String index(){
        return "mail";
    }

    @PostMapping("/login")
    public String main(@RequestParam("user_name") String username, String password, HttpSession session, Model model){
        if ("admin".equals(username) && "123".equals(password)){
//            session.setMaxInactiveInterval(10);
            session.setAttribute("token",true);
            session.setAttribute("username",username);
            return "redirect:/main.html";
        }else {
            model.addAttribute("msg","用户名或密码错误！");
            return "login";
        }
    }
}
